package com.taotao.service.impl;

import com.taotao.aop.TaoTaoManage;
import com.taotao.service.TaoTaoService;
import com.taotao.utils.RedisService;
import com.taotao.utils.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangjin
 * @CreateTime: 2022-07-26  21:38
 */
@RestController
@Slf4j
public class TaoTaoServiceImpl {
    @Autowired
    private TaoTaoManage taoManage;

    @Autowired
    private RedisService redisService;

    @RequestMapping("/addTaoTao")
    public String addTaoTao() {
        log.info(String.valueOf(this));
        TaoTaoServiceImpl taoTaoServiceImpl = SpringUtils.getBean(TaoTaoServiceImpl.class);
        log.info("<addTaoTao--start........>");
        // taoManage.addAsyncUser();
        // taoTaoServiceImpl.addAsyncUser();
        boolean flag = redisService.setIfAbsent("eee", "2222");

        System.out.println(flag + "*****");
        this.addAsyncUser();
        log.info("<addTaoTao--end........>");
        return "OK";
    }

    /**
     * 我们在使用异步注解的时候 应该注意将异步代码抽取单点一个类来进行调用该方法
     */
    @Async
    public void addAsyncUser() {
        log.info("<addAsyncUser>");
    }
}
